home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CD ROM Paradise Collection 4
/
CD ROM Paradise Collection 4 1995 Nov.iso
/
program
/
swagd_f.zip
/
DRIVES.SWG
/
0008_DRIVES3.PAS.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1993-05-28
|
1KB
|
47 lines
{ JW│ How do I detect active drives in Pascal? My Program would crash if you
│ Typed in a non-existent drive as either source or destination.
Here's the method I use:
}
Uses
Dos;
Var
Isthere : Boolean;
Function ChangeDrive( drv: Char ): Boolean;
(*
Takes drive letter as parameter, returns True if change
succeeded, False if change failed (invalid drive)
*)
Var
Regs: Dos.Registers;
NewDrv: Byte;
begin
(* Calculate drive code For desired drive *)
NewDrv := orD( UpCase( drv ) ) - orD( 'A' ); (* A: = 0 *)
(* Change drive *)
Regs.DL := NewDrv;
Regs.AH := $0E; (* Function 0Eh: Select Disk *)
MSDos( Regs );
(* See if the change 'took' *)
Regs.AH := $19; (* Function 19h: Get current drive *)
MSDos( Regs );
ChangeDrive := (Regs.AL = NewDrv);
end; (* ChangeDrive *)
begin
isthere := ChangeDrive('a');
Writeln ('a: ',isthere);
isthere := ChangeDrive('b');
Writeln ('b: ',isthere);
isthere := ChangeDrive('c');
Writeln ('c: ',isthere);
isthere := ChangeDrive('d');
Writeln ('d: ',isthere);
isthere := ChangeDrive('e');
Writeln ('e: ',isthere);
end.